<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | General Form Elements</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/font-awesome/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/Ionicons/css/ionicons.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/adminlte/dist/css/AdminLTE.min.css}">
    <link rel="stylesheet" th:href="@{/bootstrap-table/bootstrap-table.min.css}">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="@{/adminlte/dist/css/skins/_all-skins.min.css}">
    <link rel="stylesheet" th:href="@{/bootstrap-table/bootstrap-table.css}">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script  th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <script  th:src="@{/adminlte/bower_components/jquery/dist/jquery.min.js}"></script>
    <!-- Bootstrap 3.3.7 -->
    <script  th:src="@{/adminlte/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
    <script  th:src="@{/layui/layui.js}"></script>
    <!-- FastClick -->
    <script  th:src="@{/adminlte/bower_components/fastclick/lib/fastclick.js}"></script>
    <!-- AdminLTE App -->
    <script  th:src="@{/adminlte/dist/js/adminlte.min.js}"></script>
    <!-- AdminLTE for demo purposes -->
    <script  th:src="@{/adminlte/dist/js/demo.js}"></script>
    <script th:src="@{/bootstrap-table/bootstrap-table.min.js}"></script>
    <script th:src="@{/bootstrap-table/locale/bootstrap-table-zh-CN.js}"></script>

    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">



<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper" style="margin-left: 200px;">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            商品 管理
            <small>Preview</small>
        </h1>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box box-info">
                    <div class="box-body">
                        <div id="toolbar">
                            <div class="form-inline" role="form">
                                <div class="form-group">
                                    <label for="keyword">商品名称: </label>
                                    <input name="keyword"  class="form-control" type="text" id="keyword" placeholder="请输入关键字进行查询">
                                </div>
                                <label for="dictionaryid">商品种类</label>
                                <input name="dictionaryid"  class="form-control" type="text" id="dictionaryid" placeholder="请输入商品类别进行查询">
                                <button id="searchBtn" type="submit" class="btn btn-primary" style="margin-left: 5px">
                                    查询
                                </button>
                                <input type="button" value="刷新" onclick="replaceDoc()" class="btn btn-primary" style="margin-left: 5px">
                                <a href="/product/product_insert">
                                    <button id="createBtn" type="submit" class="btn btn-info" style="margin-left: 30px">
                                        插入
                                    </button>
                                </a>
<!--                                      <&#45;&#45; <a href="/Dictionary/dictionary_add">-->
<!--                                    <button class="btn" id="edit_table_btn"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>-->
<!--                                </a>-->

                                <!--                                    <a href="/user/deleteuser">-->
                                <!--                                        <button id="deleteBtn" type="submit" class="btn btn-danger">删除</button>-->
                                <!--                                    </a>-->
                            </div>
                        </div>
                        <table id="dataTable" class="table table-hover table-responsive"
                               style="table-layout: fixed"></table>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
   <script>


        $('#dataTable').bootstrapTable({
            method: 'get',//AJAX
            url: "/product/api/searchproduct",
            toolbar: '#toolbar',
            striped: true,
            dataField: "products",
            pageNumber:1,
            cache:false,
            pagination: true,
            queryParamsType: 'limit',
            queryParams: queryParams,
            sidePagination: 'server',
            pageSize: 5,
            pageList: [10, 10, 10, 100],
            showRefresh: false,
            clickToSelect: true,
            toolbarAlign: 'left',
            buttonsAlign: 'right',
            showColumns: true,
            columns: [
                {
                    title: '全选',
                    field: 'select',
                    checkbox: true,
                    width: 5,
                    align: 'center',
                },
                {
                    title: 'ID',
                    field: 'pId',
                    visible: false,
                    sortable: true,
                    width: 10
                },
                {
                    title: '商品名称',
                    field: 'productName',
                    width: 60,
                    align: 'center',
                    sortable: true
                },
                {
                    title: '商品价格',
                    field: 'money',
                    width: 60,
                    align: 'center',
                    sortable: true
                },
                {
                    title: '商品描述',
                    field: 'content',
                    width: 100,
                    align: 'center',
                    sortable: true
                },
                {
                    title:'商品图片' ,
                    field:'productPic',
                    width:80,
                    align:'center',
                    formatter:function (value, row, index, field) {
                        var str="";
                        str= "<img style=\"height: 80px;width: 80px;\" src=\""+value+"\"/>";
                        return '<img src='+value+' width="50" height="50" class="img-rounded">';
                    }
                },
                {
                    title: '商品库存',
                    field: 'num',
                    width: 50,
                    align: 'center',
                    sortable: true
                },
                {
                    title: '商品打折',
                    field: 'dazhe',
                    width: 50,
                    align: 'center',
                    sortable: true
                },
                {
                    title: '商品类id',
                    field: 'dictionaryid',
                    width: 50,
                    align: 'center',
                    sortable: true
                },
                {
                    title: 'Edit',
                    width: 20,
                    formatter: function (value, row, index, field) {
                        return [
                            '<a class="edit ml10" href="javascript:void(0)" title="Edit">',
                            '<i class="glyphicon glyphicon-edit"></i>',
                            '</a>',
                        ].join('');
                    },
                    events: {
                        'click .edit': function (e, value, row, index) {
                           // window.location.href = '/product/product_edit?pId=' + row.pId;
                            edit(row.pId);
                        }
                    },
                    align: 'center'
                },
                {
                    title: 'Delete',
                    width: 20,
                    formatter: function (value, row, index, field) {
                        return [
                            '<a class="cancel ml10" href="javascript:void(0)" title="Delete">',
                            '<i class="glyphicon glyphicon-remove"></i>',
                            '</a>',
                        ].join('');
                    },
                    events: {
                        'click .cancel': function (e, value, row, index) {
                            window.location.href = '/product/product_delete?pId=' + row.pId;
                        }
                    },
                    align: 'center'
                },
            ],
            locale: 'zh-CN',
            responseHandler: function (data) {
                return data;
            }
        });


         function queryParams(params) {
             return {
                 pageSize: params.limit,
                 pageNum: params.offset / params.limit + 1,
                 dictionaryid: $('#dictionaryid').val(),
                 keyword: $('#keyword').val()
             }
        }
        function edit(pId) {
            layui.use("layer",function () {
                var layer=layui.layer;
                layer.open({
                    type: 2,
                    title: '编辑信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area : ['400px' , '700px'],
                    content: '/product/product_edit?pId='+pId
                })
            })
        }
        $(document).ready(function () {
            $("#searchBtn").click(function () {
                $('#dataTable').bootstrapTable('refresh');
            });
            $("#searchBtn2").click(function () {
                $('#dataTable').bootstrapTable('refresh');
            })
        });
        function replaceDoc() {
            window.location.href='product_list';
        }

    </script>

    </body>
    </html>
